package com.adcc.ags.msgStore;

import com.adcc.ags.msgStore.healthcheck.DBHealthCheck;
import com.adcc.ags.msgStore.healthcheck.MQHealthCheck;
import com.adcc.ags.msgStore.managed.MessageForward;
import com.adcc.ags.msgStore.managed.MsgProxy;
import io.dropwizard.Application;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;

/**
 * MsgStore启动类
 */
public class App extends Application<AppConfiguration> {

    @Override
    public void initialize(Bootstrap<AppConfiguration> bootstrap) {
        super.initialize(bootstrap);
    }

    @Override
    public void run(AppConfiguration appConfiguration, Environment environment) throws Exception {
        MsgProxy.getInstance().build(environment,appConfiguration.getProxy());
        MessageForward.getInstance().build(environment,appConfiguration.getMqConnectionFactory(),appConfiguration.getDbConnectionFactory());
        environment.healthChecks().register("dbInfo", new DBHealthCheck());
        environment.healthChecks().register("mqInfo", new MQHealthCheck());
    }

    public static void main(String[] args) throws Exception {
        String[] strParams = (args == null || args.length <2) ? new String[]{"server","./MsgStore/conf/conf.yml"} : args;
        App app = new App();
        app.run(strParams);
    }
}
